package swingExtensions.dialog;

import io.github.jonestimd.swing.ButtonBarFactory;
import io.github.jonestimd.swing.ComponentResources;
import io.github.jonestimd.swing.dialog.FormDialog;
import io.github.jonestimd.swing.dialog.MessageDialog;
import net.miginfocom.swing.MigLayout;
import swingExtensions.demo.FrameDemo;

import javax.swing.*;
import java.awt.*;

public class MessageDialogDemo {

    protected JPanel createContentPanel() {
        JButton showMessage = new JButton("showMessage", null);
        showMessage.addActionListener(e -> {
            MessageDialog dialog = new MessageDialog(null, Dialog.ModalityType.DOCUMENT_MODAL);
            dialog.setPreferredSize(new Dimension(300, 500));
            dialog.pack();
            dialog.setStatusMessage("welcome to the real world~~~");
            new Thread(() -> {
                try {
                    Thread.sleep(5000);
                    SwingUtilities.invokeLater(() -> dialog.disableUI("正在执行长耗时操作..."));
                    Thread.sleep(10000);
                    SwingUtilities.invokeLater(() -> dialog.enableUI());
                } catch (Exception ex) {}
            }).start();
            dialog.setVisible(true);
        });
        ButtonBarFactory buttonBarFactory = new ButtonBarFactory();
        buttonBarFactory.add(showMessage).border(5, 5);
        return (JPanel) buttonBarFactory.get();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            MessageDialogDemo demo = new MessageDialogDemo();
            FrameDemo frameDemo = new FrameDemo(MessageDialogDemo.class.toString());
            frameDemo.setContentPane(demo.createContentPanel());
            frameDemo.setVisible(true);
        });
    }
}
